
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JFrame;
import javax.swing.Timer;

public class NEngine implements ActionListener {
	
	ArrayList<JFrame> frameList = new ArrayList<JFrame>();
	
	//creates a default frame
	public void createFrame() {
	    //Sets up the frame
	    JFrame frame = new JFrame("");
	    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	    frame.getContentPane().setLayout(new BorderLayout());

	    //Display the window.
	    frame.pack();
	    
	    //Adds the graphics panel and sets the size
	    frame.setLocationRelativeTo(null);
	    frame.setSize(new Dimension(810,635));
	    frame.setVisible(true);
	    
	    frameList.add(frame);
	}
	
	//creates a user defined frame
	public void createFrame(int width, int height, String title) {
	    //Sets up the frame
	    JFrame frame = new JFrame(title);
	    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	    frame.getContentPane().setLayout(new BorderLayout());

	    //Display the window.
	    frame.pack();
	    
	    //Adds the graphics panel and sets the size
	    frame.setLocationRelativeTo(null);
	    frame.setSize(new Dimension(width,height));
	    frame.setVisible(true);
	    
	    frameList.add(frame);
	}

	//only leaves the latest frame available
	public void removeOldFrames() {
		int l = frameList.size();
		
		for(int i = 0; i < l-1; i++) {
			frameList.remove(0).setVisible(false);
		}
	}
	
	//is called to start the game
	public void run() {
		createFrame();
		initialize();
		gameLoop();
	}
	
	//sets up initial game
	public void initialize() {
		
	}
	
	//the method run by the game 60 times a second
	public void update(){
		
	}
	
	//creates and starts the loop
	public void gameLoop() {
		Timer loopTime = new Timer(17, this);
		loopTime.setInitialDelay(100);
		loopTime.start();
	}

	//performs the loop
	public void actionPerformed(ActionEvent e) {
		update();	
	}

}
